const express = require("express");
const CONFIG = require('./config/config')
const app = express();
const router = require('./lib/routers');
const fileUpload = require('express-fileupload');
// 引入body-parser模块获取POST请求提交的数据
var bodyParser = require('body-parser');


// 配置body-parser
app.use(bodyParser.urlencoded({ limit: '50mb', extended: false }));
app.use(bodyParser.json({ limit: '50mb' }));
app.use(fileUpload({
    limits: { fileSize: 50 * 1024 * 1024 },
    createParentPath: true,
    defParamCharset: "utf8" // 添加utf8编码
}));
app.use(CONFIG.EAB, router)
app.use('/file', express.static('./file'));
app.all('*', function (req, res, next) {
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST');
    res.setHeader("Content-Type", "application/json;charset=utf-8");
    next();
})


const port = CONFIG.prot || 3000
app.listen(port, () => {
    console.log('服务启动', port);
})